package com.cs.study.homework._0226;

import com.sun.tools.javac.Main;

public class Demo3 {
    public static void main(String[] args) {
        Library book = new Library();
        book.addBook("活着","余华");
        book.displayBooks();

    }
}

class Library {
    Book[] books = new Book[10];

    public boolean addBook(String title, String author) {
        Book book = new Book(title, author);
        for (int i = 0; i < books.length; i++) {
            if (books[i] == null) {
                books[i] = book;
                return true;
            }
        }
        return false;
    }

    public void displayBooks() {
        for (int i = 0; i < books.length; i++) {
            if (books[i] == null) {
                continue;
            }
            books[i].displayInfo();
        }
    }

    static class Book {
        private String title;
        private String author;

        public Book(String title, String author) {
            this.title = title;
            this.author = author;
        }

        public void displayInfo() {
            System.out.println("书名:" + title + " 作者:" + author);
        }
    }
}

